<template>
    <div class="app-header-sticky" :class="{ show: isShow }">
        <div class="container" v-show="isShow">
            <RouterLink class="logo" to="/" />
            <AppHeaderNav key="stickyNav" />
            <div class="right">
                <RouterLink to="/">品牌</RouterLink>
                <RouterLink to="/">专题</RouterLink>
            </div>
        </div>
    </div>
</template>

<script>
// 常用工具库👇
// vue3.0组合API提供了更多逻辑代码封装的能力。@vueuse/core 基于组合API封装好用的工具函数
import { useWindowScroll } from "@vueuse/core";
import AppHeaderNav from "./app-header-nav.vue";
import { computed } from "vue";
export default {
  name: "AppHeaderSticky",
  components: { AppHeaderNav },
  setup() {
    const { y: scrolltop } = useWindowScroll();
    const isShow = computed(() => {
      return scrolltop.value > 119
    })
    return { isShow };
  }
};
</script>

<style scoped lang="less">
.app-header-sticky {
    width: 100%;
    height: 80px;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    background-color: #fff;
    border-bottom: 1px solid #e4e4e4;

    // 吸附
    transform: translateY(-100%);
    opacity: 0;

    &.show {
        transition: all 0.2s linear;
        opacity: 1;
        transform: translateY(0);
    }
    .container {
        display: flex;
        align-items: center;
    }
    .logo {
        width: 200px;
        height: 80px;
        background: url(~@/assets/images/logo.png) no-repeat right 2px;
        background-size: 160px auto;
    }
    .right {
        width: 220px;
        display: flex;
        text-align: center;
        padding-left: 40px;
        border-left: 2px solid @xtxColor;
        a {
            width: 38px;
            margin-right: 40px;
            font-size: 16px;
            line-height: 1;
            &:hover {
                color: @xtxColor;
            }
        }
    }
}
</style>
